import random
from datetime import datetime

# 	购前：
# 		钱要有：money
money = int(input('请输入您的卡余额：'))
# 		有足够商品：列表来存储list
goods = {"沙发":8, "被子":1, "酸奶":10,"显卡":500,"电视":2000,"洗衣机":3000,"冰箱":4000,"空调":2500,"电脑":5000,"手机":300}
# 		有购物车：列表list
car = []
#   折扣
discount = {"沙发":0.9, "被子":0.9, "酸奶":0.8,"显卡":0.8,"电视":0.9,"洗衣机":0.4,"冰箱":0.7,"空调":0.8,"电脑":0.9,"手机":0.6}
# 随机选出一个折扣：
a = random.choice(list(discount.keys())) 
print(f"恭喜，您获得了{a}的折扣为{discount[a]}折")
# 更新商品价格
goods[a] = goods[a] * discount[a]
# print(goods)
# 	购中：
while True:
    # 用户输入商品名称
    item = input('请输入您想要购买的商品名称(输入Q/q退出),或是想退货输入T/t:')
    # 退出条件
    if item.lower() == 'q':
        break
    #    退货
    if item.lower() == 't':
        print("退货商品：")
        item = input("请输入您想退货的商品：")
        if item in car:
            money += goods[item]
            car.remove(item)
            print(f"退货成功！您的卡余额还剩{money}元")
            continue
        else:
            print("你的购物车中没有该商品")
            continue
    else: 
    # 检查商品是否存在
        if item in goods.keys():
        
        # 检查钱是否足够   
            if money >= goods[item]:  
                car.append(item)
                money -= goods[item]
                print(f"恭喜，购买成功！您的卡余额还剩{money}元")
            else:
                print("穷鬼，钱不够！请到其他超市购买！")
        else:
            print("没有这个商品，别瞎弄！")
            
# 	购后：
# 		打印购物小条！
print("----------------购物小条：-----------------")
s=set(car)
print("商品名称\t数量")
for item in s:
    print(item,":",end="\t\t")
    print(car.count(item))
# 		打印总计
print("总计:",sum(goods[item] for item in car))
print("-----------" ,datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"-----------")